
/**
 * @file drv_timer.h
 * @brief This file contains all the functions prototypes for the drv_timer
 *          firmware library.
 * @author He Shaohua (hsh15529870639@foxmail.com)
 * @date 2024-05-20
 * @version 1.0
 * @copyright Copyright (c) 2024, SNUT-Chaoyue Team
 * ****************************************************************************************************
 * @par Change Log:
 * <table>
 * <tr><th>Date         <th>Version       <th>Author      <th>Description
 * <tr><td>2024-05-20   <td> 1.0          <td>He Shaohua  <td>Creator
 *
 * </table>
 * ==================================----How to use this driver----=====================================
 * [..]
 * @note
 *   -#
 *
 * @warning
 *   -#
 *
 * *****************************************************************************************************
 * @attention
 *
 * This document is required and please understand any bugs that may occur in the document.
 * If you want to modify this file, after the code update is completed, update the version number in time,
 * indicate the update date, and fill in the changes
 * Make sure that the submitted code does not have many bugs.
 *
 * All rights reserved.
 * *****************************************************************************************************
 */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ALG_PID_h
#define __ALG_PID_h
/* Includes ------------------------------------------------------------------*/
#include "drv_timer.h"
/* Exported types ------------------------------------------------------------*/
typedef enum
{
  NONE = 0X00,                // 无
  Dead_Zone = 0x02,           // 死区控制
  Trapezoid_Intergral = 0x04, // 梯形积分
  DerivationFilter = 0x08,    // 微分滤波
} PID_Increase_Mode_Typedef;

typedef struct
{
  uint32_t last_time;
  // 初始化数据
  float K_p;            /* 比例项增益 */
  float K_i;            /* 积分项增益 */
  float K_d;            /* 微分项增益 */
  float i_limit;        /* 积分项上限 */
  float out_limit_low;  /* 输出绝对值下限 */
  float out_limit_high; /* 输出绝对值上限 */
  float dead_zone;      /* 死区阈值 */
  float Derivative_LPF_RC;

  float last_error; // 上一次误差
  float pre_error;  // 上上一次误差
  float d_out;      // 上一次微分输出值
  float last_output;
  PID_Increase_Mode_Typedef mode;

} PID_Increase_Instance;

typedef struct
{
  float K_p;            /* 比例项增益 */
  float K_i;            /* 积分项增益 */
  float K_d;            /* 微分项增益 */
  float i_limit;        /* 积分项上限 */
  float out_limit_low;  /* 输出绝对值下限 */
  float out_limit_high; /* 输出绝对值上限 */
  float dead_zone;      /* 死区阈值 */
  float Derivative_LPF_RC;

} PID_Increase_Param_Config_Typedef;

/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
PID_Increase_Instance *
PIDInit(PID_Increase_Param_Config_Typedef *config, PID_Increase_Mode_Typedef mode);
float PIDCalculate(PID_Increase_Instance *pid, float measure, float Target);
void PIDReset(PID_Increase_Instance *pid);
#endif /* __ALG_PID_h */

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */
/*********************************END OF FILE*********************************/
